package org.example.gxpt.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.example.gxpt.common.result.Result;
import org.example.gxpt.pojo.dto.ShowroomDTO;
import org.example.gxpt.pojo.dto.ShowroomUpdateDTO;
import org.example.gxpt.pojo.entity.Showroom;
import org.example.gxpt.service.ShowroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/showroom")
@Slf4j
@Api(tags = "展厅相关接口")
@CrossOrigin
public class ShowroomController {

    @Autowired
    private ShowroomService showroomService;

    /**
     * 保存展厅
     * @param showroomDTO
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("保存展厅")
    public Result saveShowroom(@RequestBody ShowroomDTO showroomDTO){

        return showroomService.saveShowroom(showroomDTO);
    }

    //todo 1
    @PutMapping("/updateByContext")
    @ApiOperation("根据当前上下文更新展厅(展厅管理员使用)")
    public Result updateByContext(@RequestBody ShowroomUpdateDTO showroomUpdateDTO){
        return showroomService.updateByContext(showroomUpdateDTO);
    }

    @PutMapping("/updateById")
    @ApiOperation("根据id更新展厅(上一级管理员使用)")
    public Result updateById(@RequestBody ShowroomUpdateDTO showroomUpdateDTO){
        return showroomService.updateById(showroomUpdateDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询展厅")
    public Result<Showroom> getShowroomById(@PathVariable Long id){
        return showroomService.getShowroomById(id);
    }

    @GetMapping("/listAll")
    @ApiOperation("查询所有展厅")
    public Result<List<Showroom>> listAll(){
        return showroomService.listAll();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除展厅")
    public Result deleteShowroom(@PathVariable Long id){
        return showroomService.deleteShowroom(id);
    }

    //todo 根据地址查询展厅
        //todo AddressQueryDTO
    //todo 分页查询展厅
}
